{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-1"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import cv2\n",
    "import numpy as np\n",
    "import random\n",
    "# 毛玻璃效果：随机选取像素周围一定区域内的其他像素rgb值来代替该像素\n",
    "img = cv2.imread('image0.jpg',1)\n",
    "imgInfo = img.shape\n",
    "height = imgInfo[0]\n",
    "width = imgInfo[1]\n",
    "dstImg = np.zeros((height,width,3),np.uint8)\n",
    "# 设置像素点随机选取范围\n",
    "mm = 8\n",
    "# 更新以后的图片大小为（width-mm）*（height-mm），则图像比原来的小，会出现黑边\n",
    "# 若不-mm则会出现越界报错\n",
    "for m in range(0,height-mm):\n",
    "    for n in range(0,width-mm):\n",
    "        # 随机产生一个0-8之间的数据\n",
    "        index = int(random.random()*8)\n",
    "        (b,g,r) = img[m+index,n+index]\n",
    "        dstImg[m,n] = (b,g,r)\n",
    "cv2.imshow('dstImg',dstImg)\n",
    "cv2.waitKey(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
